package com.lczc.soa.config;

import com.lczc.soa.filter.SensitiveWordsFilter;
import com.lczc.soa.filter.SyslogFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;

import javax.servlet.DispatcherType;
import java.util.EnumSet;

/**
 * Created by Janus on 2019/8/3.
 */
@Configuration
public class MyFilterConfig {

    @Bean(name="syslogFilter")
    public SyslogFilter syslogFilter(){
        return new SyslogFilter();
    }
    @Bean(name="sensitiveWordsFilter")
    public SensitiveWordsFilter sensitiveWordsFilter(){
        return new SensitiveWordsFilter();
    }

    @Bean
    public FilterRegistrationBean sysVisitFilterBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new DelegatingFilterProxy("syslogFilter"));
        registrationBean.addInitParameter("targetFilterLifecycle","true");
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico");
        registrationBean.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST));
        registrationBean.setEnabled(false);
        return registrationBean;
    }
}
